package com.lsege.util;

import com.aliyun.oss.OSSClient;
import org.springframework.web.multipart.MultipartFile;

import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.UUID;

/**
 * Created by Administrator on 2017/7/21 0021.
 */
public class OssUtil {
    public static String uploadFile(MultipartFile file)  {
        String url = "";
       try {
           // endpoint以杭州为例，其它region请按实际情况填写
           String endpoint = "oss-cn-shanghai.aliyuncs.com";
           // accessKey请登录https://ak-console.aliyun.com/#/查看
           String accessKeyId = "UXuv5cqAv2ENbUTG";
           String accessKeySecret = "LUCijQdDKbM5hbiS9wI5e46cZwus2w";
           // 创建OSSClient实例
           OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
           // 上传文件流

           UUID uid= UUID.randomUUID();
           String path="image/prize/"+uid+".jpg";
           ossClient.putObject("looking-for-toilet", path, file.getInputStream());
           // 关闭client
           ossClient.shutdown();
            url="/image/prize/"+uid+".jpg";
       }catch (Exception e){
           e.printStackTrace();
       }
        return url;
    }
}
